package com.yikaiye.android.yikaiye.ui.fragment;

import android.os.Bundle;

import com.yikaiye.android.yikaiye.R;
import com.yikaiye.android.yikaiye.base.BaseFragment;
import com.yikaiye.android.yikaiye.config.Constant;
import com.yikaiye.android.yikaiye.databinding.FragmentInvoiceInfoBinding;
import com.yikaiye.android.yikaiye.ui.activity.mine.viewmodel.CompanyDetailsViewModel;
import com.yikaiye.android.yikaiye.ui.adapter.BillInfoAdapter;

/**
 * 开票内容
 */
public class CompanyInvoiceInfoFragment extends BaseFragment<FragmentInvoiceInfoBinding, CompanyDetailsViewModel> {

    private BillInfoAdapter adapter;

    public static CompanyInvoiceInfoFragment newInstance(String creditNo) {
        Bundle bundle = new Bundle();
        bundle.putString(Constant.CREDIT_NO_KEY, creditNo);
        CompanyInvoiceInfoFragment fragment = new CompanyInvoiceInfoFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected CompanyDetailsViewModel bindModel() {
        return getViewModel(this, CompanyDetailsViewModel.class);
    }

    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void lazyLoadData() {
        adapter = new BillInfoAdapter(mContext);
        binding.recyclerView.setAdapter(adapter);
        adapter.setEmptyViewEnable(true);
        adapter.setEmptyViewLayout(mContext, R.layout.layout_empty_list);

        if (getArguments() != null) {
            String creditNo = getArguments().getString(Constant.CREDIT_NO_KEY);
            viewModel.getInvoiceList(creditNo);
        }
    }

    @Override
    protected void initClick() {
        viewModel.invoiceRecordsModelMutableLiveData.observe(this, invoiceRecordsModel -> {
            if (invoiceRecordsModel != null) {
                adapter.submitList(invoiceRecordsModel.getRecords());
            }
        });
    }
}
